package com.mtnz.njk.Util;


import cn.hutool.core.util.IdUtil;
import com.mtnz.njk.Mapper.CommentAskMapper;
import com.mtnz.njk.Mapper.CommunityUserMapper;
import com.mtnz.njk.Mapper.NewsMapper;
import com.mtnz.njk.entity.CommentAskEntity;
import com.mtnz.njk.entity.NewsEntity;
import com.mtnz.njk.entity.NjkUserEntity;

import javax.annotation.Resource;

public class ReplyCommentAsk implements Runnable {

    private String userId;
    private String askId;
    private String message;
    private String commentAskId;
    private String url;
    @Resource(name = "commentAskMapper")
    private CommentAskMapper commentAskMapper;
    @Resource(name = "userMapper")
    private CommunityUserMapper userMapper;
    @Resource(name = "newsMapper")
    private NewsMapper newsMapper;

    public ReplyCommentAsk(String userId, String askId, String message, String commentAskId, CommentAskMapper commentAskMapper, CommunityUserMapper userMapper, NewsMapper newsMapper, String url) {
        this.userId = userId;
        this.askId = askId;
        this.message = message;
        this.commentAskId = commentAskId;
        this.commentAskMapper = commentAskMapper;
        this.userMapper = userMapper;
        this.newsMapper = newsMapper;
        this.url = url;
    }

    public synchronized void run() {
        // TODO Auto-generated method stub
        try {
            CommentAskEntity commentAskEntity = new CommentAskEntity();
            commentAskEntity.setUserId(userId);
            commentAskEntity.setAskId(askId);
            commentAskEntity.setMessage(message);
            commentAskEntity.setCommentAskId(commentAskId);
            CommentAskEntity commentAskEntity1 = commentAskMapper.selectByPrimaryKey(commentAskId);
            NjkUserEntity byId1 = userMapper.findById(userId);
            //保存消息
            NewsEntity newsEntity = new NewsEntity();
            newsEntity.setNewsId(IdUtil.simpleUUID());
            newsEntity.setId(commentAskEntity1.getAskId());
            newsEntity.setMessage(message);
            newsEntity.setName(byId1.getNickName());
            newsEntity.setImg(byId1.getImg());
            newsEntity.setCreateDate(cn.hutool.core.date.DateUtil.now());
            newsEntity.setUserId(commentAskEntity1.getUserId());
            newsEntity.setSubject(commentAskEntity1.getMessage());
            newsEntity.setStatus("1");
            newsEntity.setUserId1(userId);
            newsEntity.setUrl(url);
            newsMapper.insert(newsEntity);
            NjkUserEntity njkUserEntity = userMapper.selectByPrimaryKey(userId);
            njkUserEntity.setStatus("1");
            userMapper.updateByPrimaryKeySelective(njkUserEntity);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }


}
